﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dispatcher.Presenter;
using SilverlightShared;

namespace Dispatcher
{
    public interface IActiveJobView
    {
        object ActiveJobDataSource { set; }
    }

    public class JobActiveModelView
    {
        public int ID { get; set; }
        public string Taxi { get; set; }
        public DateTime TimeRequested { get; set; }
        public string TaxiCompany { get; set; }
        public string CustomerName { get; set; }
        public string Pickup { get; set; }
        public string Destination { get; set; }
        public string DeclinedDrivers { get; set; }
        public string VehicleRequested { get; set; }
    }

    public class ActivJobPresenter : GenericPresenter
    {
        #region Private Variables
		private IActiveJobView _View;
	    #endregion

        #region Constructor & Destructor
        public ActivJobPresenter(IActiveJobView view) : base()
        {
            _View = view;
        }
        #endregion

        #region Public Fn
        public override void Present ()
        {
            var activeJobs = from jobs in DAL.ListItEntities.ActiveJobs
                                 select new
                                 {
                                     ID = jobs.ID,
                                     Taxi = jobs.Taxi.LicenseNo,
                                     TimeRequested = jobs.TimeRequested,
                                     TaxiCompany = jobs.Taxi.TaxiCoy.CompanyName,
                                     VehicleType = jobs.VehicleType,
                                     CustomerName = jobs.CustomerName,
                                     Pickup = jobs.PickupAddress,
                                     Destination = jobs.DestinationAddress
                                 };

            List<JobActiveModelView> viewList = new List<JobActiveModelView>();

            foreach (var job in activeJobs)  {
                TaxiType taxiType = (TaxiType)job.VehicleType;

                viewList.Add(
                    new JobActiveModelView {
                        ID = job.ID,
                        Taxi = job.Taxi,
                        TimeRequested = job.TimeRequested,
                        TaxiCompany = job.TaxiCompany,
                        VehicleRequested = TaxiCommon.GetVehicleType(taxiType),
                        CustomerName = job.CustomerName,
                        Pickup = job.Pickup,
                        Destination = job.Destination
                    });
            }

            _View.ActiveJobDataSource = viewList;
        }
        #endregion
    }
}
